#include <iostream>
#include <string>
#include <memory>
class Fruit
{

public:
    virtual void getname() = 0;
};

class Banana : public Fruit
{
public:
    void getname() override
    {
        std::cout << "我是一个香蕉" << std::endl;
    }
};

class Apple : public Fruit
{
public:
    void getname() override
    {
        std::cout << "我是一个苹果" << std::endl;
    }
};

class Factory
{
   public:
   Factory(){}
       virtual std::shared_ptr<Fruit>create()=0;


};

class AppleFactory:public Factory{


    public:
    AppleFactory(){}
        std::shared_ptr<Fruit>create()override{
 
              return std::shared_ptr<Apple>(new Apple());

        }
     
};

class BananaFactory:public Factory{


    public:
    BananaFactory(){ }
      std::shared_ptr<Fruit>create()override{
 
              return std::shared_ptr<Banana>(new Banana());

        }
     
};
int main()
{   
      std::shared_ptr<Factory> F1(new AppleFactory());
      std::shared_ptr<Fruit> fruit1= F1->create();
      fruit1->getname();

       std::shared_ptr<Factory> F2(new BananaFactory());
      std::shared_ptr<Fruit> fruit2= F2->create();
      fruit2->getname();
   
    return 0;
}
